<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>交易流水</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="{{asset('/layuiadmin/layui/css/layui.css')}}" media="all">
    <link rel="stylesheet" href="{{asset('/layuiadmin/style/admin.css')}}" media="all">
    <style>
        .edit{background-color: #ed9c3a;}
        .shenhe{background-color: #429488;}
        .see{background-color: #7cb717;}
        .tongbu{background-color: #4c9ef8;color:#fff;border-radius:3.5px}
        .cur{color:#21c4f5;}
        .userbox,.storebox{height:190px;margin-right:0; overflow-y: auto; z-index: 999; position: absolute; left: 0px; top: 63px; width:298px; background-color:#ffffff; border: 1px solid #ddd;}
        .userbox .list,.storebox .list{height:38px;line-height: 38px;cursor:pointer; padding-left:10px;}
        .userbox .list:hover,.storebox .list:hover{background-color:#eeeeee;}
        .yname{font-size: 13px; color: #444; margin-bottom:8px;}
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12" style="margin-top:0px">
            <div class="layui-fluid">
                <div class="layui-row layui-col-space15">
                    <div class="layui-col-md12">
                        <div class="layui-card">
                            <div class="layui-card-header">新增商户流水</div>
                            <div class="layui-card-body">
                                <div class="layui-btn-container" style="font-size:14px;">
                                    <div style="font-size:14px">
                                        <div class="layui-form" lay-filter="component-form-group" style="width: 100%;margin-right:0;display: inline-block;">
                                            <div class="layui-form-item">
                                                <div class="layui-input-block" style="margin-left:5px;border-radius:5px">

{{--                                                    <div class="layui-input-block" style="margin-left:5px;border-radius:5px">--}}
{{--                                                        <text class="yname">门店名称</text>--}}
{{--                                                        <input type="text" style="border-radius:5px; width: 300px; display: inline-block;" name="schoolname" lay-verify="schoolname" autocomplete="off" placeholder="请输入门店名称" class="layui-input inputstore">--}}
{{--                                                        <div class="storebox" style='display: none'></div>--}}
{{--                                                    </div>--}}

{{--                                                    <div class="layui-inline">--}}
{{--                                                        <button class="layui-btn layuiadmin-btn-list" lay-submit="" lay-filter="LAY-app-contlist-search" style="border-radius:5px;margin-top:0px;margin-bottom: 0;height:36px;line-height: 36px;">--}}
{{--                                                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>--}}
{{--                                                        </button>--}}
{{--                                                    </div>--}}


                                                    <div class="layui-inline">
                                                        <div class="layui-input-inline">
                                                            <text class="yname">交易开始时间</text>
                                                            <input type="text" class="layui-input start-item test-item" placeholder="交易开始时间" lay-key="23">
                                                        </div>
                                                    </div>
                                                    <div class="layui-inline">
                                                        <div class="layui-input-inline">
                                                            <text class="yname">交易结束时间</text>
                                                            <input type="text" class="layui-input end-item test-item" placeholder="交易结束时间" lay-key="24">
                                                        </div>
                                                    </div>

                                                    <!-- <div class="layui-inline">
                                                        <div class="layui-input-inline">
                                                            <text class="yname">门店名称</text>
                                                            <input type="text" class="layui-input store_name test-item" placeholder="门店名称">
                                                        </div>
                                                    </div> -->
                                                    <div class="layui-inline">
                                                        <div class="layui-input-inline" style="margin-left:5px;border-radius:5px;width: 300px;">
                                                            <text class="yname">门店名称</text>
                                                            <input type="text" style="border-radius:5px; width: 300px; display: inline-block;" name="schoolname" lay-verify="schoolname" autocomplete="off" placeholder="请输入门店名称" class="layui-input inputstore">
                                                            <div class="storebox" style='display: none'></div>
                                                        </div>
                                                    </div>

                                                    <div class="layui-inline">
                                                        <button class="layui-btn layui-btn-normal" style="border-radius:5px;margin-top:31px;" id="search">搜索</button>

                                                        <button class="layui-btn export" style="border-radius:5px;margin-top:31px;">导出</button>
                                                    </div>

                                                </div>



                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <table class="layui-hide" id="test-table-page" lay-filter="test-table-page"></table>

                                <!-- 判断状态 -->
                                <script type="text/html" id="statusTap">
                                    @{{#  if(d.pay_status == 1){ }}
                                    <span class="cur">@{{ d.pay_status_desc }}</span>
                                    @{{#  } else { }}
                                    @{{ d.pay_status_desc }}
                                    @{{#  } }}
                                </script>
                                <!-- 判断状态end -->

                                <!-- 判断状态 -->
                            {{--<script type="text/html" id="moneyTap">--}}
                            {{--@{{#  if(d.pay_status_desc == "已退款"){ }}--}}
                            {{--<span class="curs">@{{ d.refund_amount }}</span>--}}
                            {{--@{{#  } else { }}--}}
                            {{--@{{ d.refund_amount }}--}}
                            {{--@{{#  } }}--}}
                            {{--</script>--}}
                            <!-- 判断状态 end -->

                                <script type="text/html" id="paymoney">
                                    @{{ d.rate }}%
                                </script>

                                <!-- 积分抵扣 -->
                                <script type="text/html" id="jfdkTap">
                                    @{{ d.dk_jf }}/@{{ d.dk_money }}
                                </script>

                                <!-- 通道类型 -->


                                <script type="text/html" id="table-content-list" class="layui-btn-small">
                                    <a class="layui-btn layui-btn-normal layui-btn-xs tongbu" lay-event="tongbu">同步状态</a>
                                </script>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<input type="hidden" class="store_id">
<input type="hidden" class="sort">
<input type="hidden" class="stu_class_no">

<input type="hidden" class="stu_order_batch_no">
<input type="hidden" class="user_id">

<input type="hidden" class="pay_status">
<input type="hidden" class="pay_type">

<input type="hidden" class="paycode">
<input type="hidden" class="company_id">

<input type="hidden" class="sbid">
<input type="hidden" class="danhao">
<input type="hidden" class="tiaoma">

<script src="{{asset('/layuiadmin/layui/layui.js')}}"></script>
<script>
    var token = localStorage.getItem("Usertoken");
    var str=location.search;
    var store_id=str.split('?')[1];

    layui.config({
        base: '../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form','table','laydate'], function(){
        var $ = layui.$
            ,admin = layui.admin
            ,form = layui.form
            ,table = layui.table
            ,laydate = layui.laydate;

        $('.store_id').val(store_id);

        // 未登录,跳转登录页面
        $(document).ready(function(){
            if(token==null){
                window.location.href="{{url('/user/login')}}";
            }
        });

        var s_storename=localStorage.getItem('s_storename');

        if(store_id == undefined){

        }else{
            $('.inputstore').val(s_storename);
        }

        $(".transfer").bind("input propertychange",function(event){
            //         console.log($(this).val());
            user_name = $(this).val();
            if (user_name.length == 0) {
                $('.userbox').html('');
                $('.userbox').hide();
            } else {
                $.post("{{url('/api/user/get_sub_users')}}",
                    {
                        token:token
                        ,user_name:$(this).val()
                        ,self:'1'
                    },function(res){
                        var html="";

                        if(res.t==0){
                            $('.userbox').html('');
                        }else{
                            for(var i=0;i<res.data.length;i++){
                                html+='<div class="list" data='+res.data[i].id+'>'+res.data[i].name+'-'+res.data[i].level_name+'</div>'
                            }
                            $(".userbox").show();
                            $('.userbox').html('');
                            $('.userbox').append(html);
                        }
                    },"json");
            }
        });

        $(".userbox").on("click",".list",function(){
            $('.transfer').val($(this).html());
            $('.user_id').val($(this).attr('data'));
            $('.userbox').hide();

            table.reload('test-table-page', {
                where: {
                    user_id:$(this).attr('data'),
                    store_id:$('store_id').val()
                }
                ,page: {
                    curr: 1
                }
            });
        });

        $(".inputstore").bind("input propertychange",function(event){
            var store_name = $(this).val();
            if (store_name.length == 0) {
                $('.storebox').html('');
                $('.storebox').hide();
                $('.store_id').val('')
            } else {
                $.post("{{url('/api/user/store_lists')}}",
                {
                    token:token
                    ,store_name:$(this).val()
                    ,l:100
                },function(res){
                    var html="";
                    if(res.t==0){
                        $('.storebox').html('');
                    }else{
                        for(var i=0;i<res.data.length;i++){
                            html+='<div class="list" data='+res.data[i].store_id+'>'+res.data[i].store_name+'</div>'
                        }
                        $(".storebox").show();
                        $('.storebox').html('');
                        $('.storebox').append(html);
                    }
                },"json");
            }
        });

        $(".storebox").on("click",".list",function(){
            $('.inputstore').val($(this).html());
            $('.store_id').val($(this).attr('data'));
            $('.storebox').hide();

            // table.reload('test-table-page', {
            //     where: {
            //         user_id:$('user_id').val(),
            //         store_id:$(this).attr('data')
            //     }
            //     ,page: {
            //         curr: 1
            //     }
            // });

            // $("#passway").html('');

        });



        table.on('tool(test-table-page)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var e = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            //          console.log(e);
            // localStorage.setItem('s_store_id', e.store_id);

            if(layEvent === 'tongbu'){ //同步
                $.post("{{url('/api/basequery/update_order')}}",
                    {
                        token:token
                        ,store_id:e.store_id
                        ,out_trade_no:e.out_trade_no
                    },function(res){
                        if(res.status==1){
                            layer.msg(res.message, {
                                offset: '50px'
                                ,icon: 1
                                ,time: 2000
                            });
                        }else{
                            layer.msg(res.message, {
                                offset: '50px'
                                ,icon: 2
                                ,time: 2000
                            });
                        }
                    },"json");
            }

            var data = obj.data;
            if(obj.event === 'setSign'){
                layer.open({
                    type: 2,
                    title: '模板详细',
                    shade: false,
                    maxmin: true,
                    area: ['60%', '70%'],
                    content: "{{url('/merchantpc/paydetail?')}}"+e.stu_order_type_no
                });
            }
        });

        // 选择门店
        form.on('select(schooltype)', function(data){
            var store_id = data.value;
            $('.store_id').val(store_id);

            //执行重载
            table.reload('test-table-page', {
                where: {
                    store_id: store_id
                    ,user_id:$('.user_id').val()
                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        // 选择排序
        form.on('select(grade)', function(data){
            var sort = data.value;
            $('.sort').val(sort);

            //执行重载
            table.reload('test-table-page', {
                where: {
                    sort:sort
                }
                ,page: {
                    curr: 1//重新从第 1 页开始
                }
            });
        });

        // 是否优惠
        form.on('select(discount)', function(data){
            var discount = data.value;
            $('.discount').val(discount);

            //执行重载
            table.reload('test-table-page', {
                where: {
                    discount:discount
                }
                ,page: {
                    curr: 1//重新从第 1 页开始
                }
            });
        });

        // 选择业务员
        form.on('select(agent)', function(data){
            var user_id = data.value;
            $('.user_id').val(user_id);

            //执行重载
            table.reload('test-table-page', {
                where: {
                    user_id: $(".user_id").val()
                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });

        });

        // 选择状态
        form.on('select(status)', function(data){
            var pay_status = data.value;
            $('.pay_status').val(pay_status);

            //执行重载
            table.reload('test-table-page', {
                where: {
                    pay_status:pay_status
                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        // 选择支付类型
        form.on('select(type)', function(data){
            var pay_type = data.value;
            $('.pay_type').val(pay_type);

            //执行重载
            table.reload('test-table-page', {
                where: {
                    ways_source:pay_type
                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        // 选择通道类型
        form.on('select(passway)', function(data){
            var company_id = data.value;
            $('.company_id').val(company_id);

            //执行重载
            table.reload('test-table-page', {
                where: {
                    company:company_id
                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        laydate.render({
            elem: '.start-item'
            ,type: 'date'
            ,done: function(value){
                //执行重载
                // table.reload('test-table-page', {
                //     where: {
                //         time_start:value
                //         ,time_end:$('.end-item').val()
                //     }
                //     ,page: {
                //         curr: 1 //重新从第 1 页开始
                //     }
                // });
            }
        });

        laydate.render({
            elem: '.end-item'
            ,type: 'date'
            ,done: function(value){
                //执行重载
                // table.reload('test-table-page', {
                //     where: {
                //         time_start:$('.start-item').val()
                //         ,time_end:value
                //     }
                //     ,page: {
                //         curr: 1 //重新从第 1 页开始
                //     }
                // });
            }
        });

        //开始金额
        $('.amount_start').bind("input propertychange",function(event){
            var amount_start = parseInt($(this).val());
            var amount_end = parseInt($('.amount_end').val());

            if(amount_start<amount_end){ //开始金额
                //执行重载
                table.reload('test-table-page', {
                    where: {
                        amount_start: $(this).val()
                        ,amount_end:$('.amount_end').val()
                    }
                    ,page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
            }else if($('.amount_end').val() == ''){ //结束金额

            }else{
                // layer.msg('开始金额不能大于结束金额')
            }
        });

        //结束金额
        $('.amount_end').bind("input propertychange",function(event){
            var amount_start=parseInt($('.amount_start').val());
            var amount_end=parseInt($(this).val());
            if(amount_start<amount_end){ //开始金额
                //执行重载
                table.reload('test-table-page', {
                    where: {
                        amount_start: $('.amount_start').val()
                        ,amount_end:$(this).val()
                    }
                    ,page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
            }else if($('.amount_start').val() == ''){//结束金额

            }else{//结束金额
                // layer.msg('开始金额不能大于结束金额')
            }
        });

        form.on('submit(LAY-app-contlist-search)', function(data){

            // var paytradeno = data.field.paytradeno;  //条码单号
            // var out_trade_no = data.field.tradeno; //订单号
            // var device_id = data.field.deviceid;
            //
            // $('.danhao').val(out_trade_no);
            // $('.tiaoma').val(paytradeno);
            // $('.sbid').val(device_id);

            var store_name = $('.inputstore').val();

            //执行重载
            table.reload('test-table-page', {
                where: {
                    store_name: store_name
                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        // $('.export').click(function(){

        //     window.location.href="{{url('/api/export/merchant_turnover_last_week')}}" + "?token=" + token + "&time_start=" + $('.start-item').val() + "&time_end=" + $('.end-item').val() + "&store_name=" + $('.store_name').val();
        // });
        $('.export').click(function(){
            var exportLoading = layer.msg('数据导出中..', {
                icon: 16
                ,shade: 0.3
                ,time: false
            });
            let params = {
                token: token,
                store_created_start_date: $('.start-item').val(),
                store_created_end_date: $('.end-item').val(),
                store_id: $('.store_id').val(),
            }
            $.ajax({
                url : "{{url('/api/v2/Bill/User/Count/storeCompanyGroupCountListExport')}}",
                data : {
                    token:token,
                    ...params
                },
                dataType:'json',
                type : 'post',
                success : function(data) {
                    layer.close(exportLoading);
                    if (data.status == 1) {
                        layer.close(exportLoading);
                        let urls = data.url.replace(/http:\/\//i, 'https://');
                        window.location.href=urls;
                    } else {
                        layer.msg(data.message);
                    }
                },
                error : function(data) {
                    layer.close(exportLoading);
                    alert('查找板块报错');
                }
            });
        })

        // 搜索
        $('#search').click(function(){

            // var type = $('#agent').val();

            // console.log( $('.start-item').val() )

            // $('.start-item').val($('.starttimeY').val());
            // $('.end-item').val($('.endtimeY').val());
            var pageLoading = layer.msg('数据请求中..', {
                icon: 16
                ,shade: 0.3
                ,time: false
            });
            // 渲染表格
//             table.render({
//                 elem: '#test-table-page',
//                 url: "{{url('/api/user/merchant_turnover_last_week')}}",
//                 // url: ""
//                 method: 'post',
//                 where:{
//                     token: token,
//                     store_id: store_id,
//                     time_start: $('.start-item').val(),
//                     time_end: $('.end-item').val(),
//                     store_name: $('.store_name').val(),
//                 },
//                 request: {
//                     pageName: 'p',
//                     limitName: 'l'
//                 },
//                 page: true,
//                 cellMinWidth: 100,
//                 cols: [[
//                     {field: 'store_id', align: 'left', title: '门店id'},
//                     {field: 'store_name', align: 'left', title: '门店名称'},
//                     {field: 'company', align: 'left', title: '通道'},
//                     {field: 'total_amount', align: 'right', title: '收款总额(元)'},
//                     // {field: 'store_order_count', align: 'right', title: '订单总数'},
//                     // {field: 'refund_order_num', align: 'right', title: '退款总数'},
//                 ]],
//                 response: {
//                     statusName: 'status', //数据状态的字段名称，默认：code
//                     statusCode: 1, //成功的状态码，默认：0
//                     msgName: 'message', //状态信息的字段名称，默认：msg
//                     countName: 't', //数据总数的字段名称，默认：count
//                     dataName: 'data', //数据列表的字段名称，默认：data
//                 },
//                 done: function(res, curr, count){
// //            console.log(res);
//                     $('th').css({'font-weight': 'bold', 'font-size': '15','color': 'black','background':'linear-gradient(#f2f2f2,#cfcfcf)'});	//进行表头样式设置
//                     if(pageLoading){
//                         layer.close(pageLoading);
//                     }
//                 }
//             });

            // 2025/6/6 新接口
            table.render({
                elem: '#test-table-page',
                url: "{{url('/api/v2/Bill/User/Count/storeCompanyGroupCountList')}}",
                // url: ""
                method: 'get',
                where:{
                    token: token,
                    store_created_start_date: $('.start-item').val(),
                    store_created_end_date: $('.end-item').val(),
                    store_id: $('.store_id').val(),
                },
                request: {
                    pageName: 'page',
                    limitName: 'pagesize'
                },
                page: true,
                cellMinWidth: 100,
                cols: [[
                    {field: 'store_id', align: 'left', title: '门店id'},
                    {field: 'store_name', align: 'left', title: '门店名称'},
                    {field: 'company_name', align: 'left', title: '通道'},
                    {field: 'total_fee', align: 'right', title: '总交易金额(元)'},
                    {field: 'refund_fee', align: 'right', title: '总退款金额(元)'},
                    {field: 'store_created_at', align: 'right', title: '门店创建时间'},
                ]],
                response: {
                    statusName: 'status', //数据状态的字段名称，默认：code
                    statusCode: 1, //成功的状态码，默认：0
                    msgName: 'message', //状态信息的字段名称，默认：msg
                    countName: 'total', //数据总数的字段名称，默认：count
                    dataName: 'data', //数据列表的字段名称，默认：data
                },
                done: function(res, curr, count){
//            console.log(res);
                    $('th').css({'font-weight': 'bold', 'font-size': '15','color': 'black','background':'linear-gradient(#f2f2f2,#cfcfcf)'});	//进行表头样式设置
                    if(pageLoading){
                        layer.close(pageLoading);
                    }
                }
            });

            //执行重载
            {{--table.reload('test-table-page', {--}}
            {{--    url: "{{url('/api/user/merchant_turnover_last_week')}}",--}}
            {{--    where: {--}}
            {{--        time_start: $('.start-item').val(),--}}
            {{--        time_end: $('.end-item').val(),--}}
            {{--        // type: type--}}
            {{--    },--}}
            {{--    page: {--}}
            {{--        curr: 1 //重新从第 1 页开始--}}
            {{--    }--}}
            {{--});--}}

        });

    });
</script>

</body>
</html>